using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CMS.Presenters.Views;
using CMS.Presenters.Presenters;
using System.Collections.Generic;
using CMS.Core.Domain;
using CMS.Data;

namespace CMS.Web.Template
{
    public partial class VBAD : BaseUserControl, IVBPLView
    {
        VBPLPresenter presenter;
        IList<VanBan> objIList;
        string maChucNang = "IsVBAD";
        bool valueChucNang = true;

        public VBAD()
        {
            this.presenter = new VBPLPresenter(this, NHibernateDaoFactory.Instance.GetVanBanDao());
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            presenter.LoadViewFromModel(this.maChucNang, this.valueChucNang);
            if (!this.IsPostBack)
            {
                this.gridObj.DataSource = this.objIList;
                this.gridObj.DataBind();
            }
        }

        protected void gridObj_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.gridObj.DataSource = this.objIList;
            gridObj.PageIndex = e.NewPageIndex;
            gridObj.DataBind();
        }

        protected void gridObj_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Pager)
            {
                // Disabled control 
                foreach (GridViewRow row in gridObj.Rows)
                {
                    VanBan obj = VanBanDao.Instance.GetById(Convert.ToInt32(gridObj.DataKeys[row.RowIndex].Value.ToString()));

                }

                foreach (Control c in e.Row.Cells[0].Controls)
                {
                    if (c.GetType().ToString().Equals("System.Web.UI.WebControls.PagerTable"))
                    {
                        Table tbl = (Table)c;
                        TableCell cell = new TableCell();
                        cell.Text = "Trang ";
                        cell.HorizontalAlign = HorizontalAlign.Right;
                        tbl.Rows[0].Cells.AddAt(0, cell);
                    }
                }
            }
        }

        public string ShowFileDinhKem(string fileName)
        {
            return (!fileName.Equals("")) ? "" : "none";
        }

        #region IVBPLView Members

        public System.Collections.Generic.IList<CMS.Core.Domain.VanBan> VanBanList
        {
            get { return this.objIList; }
            set { this.objIList = value; }
        }

        #endregion
    }
}